import 'package:getx_demo/common/utils/utils.dart';
import 'package:getx_demo/pages/forgetSendSMS/index.dart';
import 'package:flutter/material.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'index.dart';

class ForgetpwdPage extends GetView<ForgetpwdController> {
  const ForgetpwdPage({Key? key}) : super(key: key);

  // 主视图
  Widget _buildView() {
    return KeyboardDismissOnTap(
      dismissOnCapturedTaps: true,
      child: Column(
        children: [
          SizedBox(height: 27.h),
          _buildPhoneNumber(),
          SizedBox(height: 62.h),
          _buildNext(),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ForgetpwdController>(
      init: ForgetpwdController(),
      id: "forgetpwd",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: const Text("忘记密码")),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }

  Container _buildPhoneNumber() {
    return Container(
      margin: EdgeInsets.only(left: 32.w, right: 32.w),
      decoration: BoxDecoration(
        //设置四周圆角 角度
        borderRadius: const BorderRadius.all(Radius.circular(4.0)),
        //设置四周边框
        border: Border.all(width: 0.5, color: '#97A1B0'.toColor()),
        color: Colors.white,
      ),
      child: SizedBox(
        height: 45,
        child: TextField(
          textAlign: TextAlign.left,
          // controller: _phoneController,
          keyboardType: TextInputType.text,
          autofocus: true,
          textInputAction: TextInputAction.done,
          style: const TextStyle(color: Colors.black, fontSize: 14),
          decoration: InputDecoration(
            contentPadding: const EdgeInsets.only(left: 13.5),
            hintText: "请输入手机号",
            border: InputBorder.none,
            hintStyle: TextStyle(color: '#B6B6B6'.toColor(), fontSize: 14),
          ),
        ),
      ),
    );
  }

  Widget _buildNext() {
    return SizedBox(
      width: ScreenUtil().screenWidth - margin * 2,
      height: 44,
      child: ElevatedButton(
        onPressed: controller.nextTap,
        style: ButtonStyle(
          shape: MaterialStateProperty.all(
            RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(22),
            ),
          ),
          overlayColor: MaterialStateProperty.resolveWith((states) {
            return Colors.transparent;
          }),
          elevation: MaterialStateProperty.all(0),
          backgroundColor: MaterialStateProperty.all('#0E67E7'.toColor()),
        ),
        child: const Text(
          '下一步',
          style: TextStyle(fontSize: 18),
        ),
      ),
    );
  }

  bool _isPhoneNumber(text) {
    RegExp exp = RegExp(
        r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$');
    bool matched = exp.hasMatch(text);
    return matched;
  }
}
